package com.example.databaseproject;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import android.widget.Toast;

import androidx.annotation.Nullable;

public class myDataBase extends SQLiteOpenHelper {

    Context context;
    public myDataBase(@Nullable Context context, @Nullable String name,  int version) {
        super(context, name, null, version);
        this.context =context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql = "Create table school(id integer primary key autoincrement,name varchar,age int)";
        db.execSQL(sql);
        db.execSQL("insert into school(name,age) values('Tom',350)");
        db.execSQL("insert into school(name,age) values('Alice',3450)");
        db.execSQL("insert into school(name,age) values('jaca',302)");
        db.execSQL("insert into school(name,age) values('xiaoming',13)");
        db.execSQL("insert into school(name,age) values('Tm',35)");
        db.execSQL("insert into school(name,age) values('om',130)");
        db.execSQL("insert into school(name,age) values('m',3)");
        db.execSQL("insert into school(name,age) values('asm',0)");
        Toast.makeText(context,"数据库创建完毕",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
